from name_function import get_formatted_name
print("enter 'q' at any time to quit.")
while True:
    first = input("\nplease give me a first name: ")
    if first == "q":
        break
    last = input("please give me a last name: ")
    if last =="q":
        break
    formatted_name = get_formatted_name(first, last)
    print("\tneatly formatted name: " + formatted_name + ".")
import unittest
from name_function import get_formatted_name
class NamesTestCase(unittest.TestCase):
    """测试name_function.py"""
    def test_first_last_name(self):
        """能够正确的处理像janis joplin这样的姓名吗"""
        formatted_name = get_formatted_name("janis", "joplin")
        self.assertEqual(formatted_name, "Janis Joplin")
    def test_first_last_middle_name(self):
        """能够正确处理wofgang amadeus mozart这样的姓名吗"""
        formatted_name = get_formatted_name(
            "wolfgang", "mozart", "amadeus")
        self.assertEqual(formatted_name,"Wolfgang Amadeus Mozart")
unittest.main()
from surver import AnonymousSurvey
#定义一个问题，并创建一个表示调查的AnonymousSurvey对象
question = "what language did you first learn to speak?"
my_survey = AnonymousSurvey(question)
#显示问题并存储答案
my_survey.show_question()
print("enter 'q' at any time to quit.\n")
while True:
	response = input("language: ")
	if response =="q":
		break
	my_survey.store_response(response)
#显示调查结果
print("\nthank you to everyone who participated in the survey!")
my_survey.show_results()
import unittest
from surver import AnonymousSurvey
class TestAnonymousSurvey(unittest.TestCase):
	def test_store_sigle_response(self):
		question = "what language did you first learn to speak?"
		my_survey = AnonymousSurvey(question)
		my_survey.store_response("Chinese")
		self.assertIn("Chinese", my_survey.responses)
	def test_store_three_response(self):
		question = "what language did you first learn to speak?"
		my_survey = AnonymousSurvey(question)
		responses = ["Chinese", "English", "Franch"]
		for response in responses:
		    my_survey.store_response(response)
		for response in responses:
		    self.assertIn(response, my_survey.responses)
import unittest
from surver import AnonymousSurvey
class TestAnonymousSurvey(unittest.TestCase):
	def setUp(self):
		"""创建一个调查对象和一组答案，供使用的测试方法使用"""
		question = "what language did you first learn to speak?"
		self.my_survey = AnonymousSurvey(question)
		self.responses = ["Chinese", "English", "Franch"]
	def test_store_sigle_response(self):
		self.my_survey.store_response(self.responses[0])
		#运行类，将结果存储进去
		self.assertIn(self.responses[0], self.my_survey.responses)
		#前面是在测试函数中提供的实例，后面是运行实例后的所有结果
	def test_store_three_response(self):
		for response in self.responses:
			self.my_survey.store_response(response)
			#将实例全部存储进入测试函数中
		for response in self.responses:
			self.assertIn(response, self.my_survey.responses)
			#在括号里的部分应该是列表，而不是函数
unittest.main()
	
